﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Users;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CurrentCart
    {
        public static void AddItemToCart(int PortalID, NB_Store_CartItemsInfo objCIInfo, HttpRequest Request = null)
        {
            CartController controller = new CartController();
            TaxCalcController controller2 = new TaxCalcController(PortalID);
            if (SharedFunctions.GetStoreSettingBoolean(PortalID, "singlepurchase.flag"))
            {
                DeleteCartItems(PortalID);
                objCIInfo.Quantity = 1;
            }
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            objCIInfo.CartID = currentCart.CartID;
            if (Request != null)
            {
                objCIInfo.ProductURL = Request.Url.OriginalString;
            }
            if (objCIInfo.Quantity > 0)
            {
                ProductTaxInfo info2 = controller2.getProductTaxDetails(PortalID, objCIInfo);
                objCIInfo.Tax = Conversions.ToDecimal(info2.TaxAmount);
                int num = CheckStock(objCIInfo.ModelID, objCIInfo.Quantity);
                if (num > 0)
                {
                    objCIInfo.Quantity = num;
                    int cartItemID = controller.UpdateObjCartItem(objCIInfo);
                    if (EventInterface.Instance() != null)
                    {
                        EventInterface.Instance().AddItemToCart(PortalID, cartItemID);
                    }
                }
            }
        }

        public static void AddItemToCart(int PortalID, DataListItem LItem, UserInfo UserInfo, HttpRequest Request = null)
        {
            AddItemToCart(PortalID, LItem, false, UserInfo, Request);
        }

        public static void AddItemToCart(int PortalID, DataListItem LItem, bool IncrementCart, UserInfo UserInfo, HttpRequest Request = null)
        {
            IEnumerator enumerator2=null;
            IEnumerator enumerator3=null;
            IEnumerator enumerator4=null;
            IEnumerator enumerator5=null;
            IEnumerator enumerator6=null;
            IEnumerator enumerator7=null;
            CartController controller = new CartController();
            int modelID = -1;
            ProductController controller2 = new ProductController();
            NB_Store_OptionInfo info2 = new NB_Store_OptionInfo();
            Collection collection2 = new Collection();
            Collection collection4 = new Collection();
            Collection collection5 = new Collection();
            Collection collection = new Collection();
            Collection collection3 = new Collection();
            int num = 1;
            Control item = LItem.FindControl("hfModel");
            if ((item != null) && Versioned.IsNumeric(((HiddenField) item).Value))
            {
                modelID = Conversions.ToInteger(((HiddenField) item).Value);
                if (SharedFunctions.IsDealer(PortalID, UserInfo, SharedFunctions.GetCurrentCulture()))
                {
                    IEnumerator enumerator=null;
                    NB_Store_ModelInfo model = controller2.GetModel(modelID, SharedFunctions.GetCurrentCulture());
                    decimal minusOne = decimal.MinusOne;
                    if (decimal.Compare(model.DealerCost, decimal.Zero) > 0)
                    {
                        minusOne = model.DealerCost;
                    }
                    ArrayList list3 = SharedFunctions.GetAvailableModelList(PortalID, model.ProductID, SharedFunctions.GetCurrentCulture(), SharedFunctions.IsDealer(PortalID, UserInfo, SharedFunctions.GetCurrentCulture()));
                    try
                    {
                        enumerator = list3.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                            if ((decimal.Compare(current.DealerCost, minusOne) < 0) & (decimal.Compare(current.DealerCost, decimal.Zero) > 0))
                            {
                                minusOne = current.DealerCost;
                                modelID = current.ModelID;
                            }
                            else if (decimal.Compare(minusOne, decimal.MinusOne) == 0)
                            {
                                minusOne = current.DealerCost;
                                modelID = current.ModelID;
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                }
            }
            item = LItem.FindControl("ddlModel");
            if (item == null)
            {
                item = LItem.FindControl("ddlModelsel");
            }
            if (((item != null) && item.Visible) && Versioned.IsNumeric(((DropDownList) item).SelectedValue))
            {
                modelID = Conversions.ToInteger(((DropDownList) item).SelectedValue);
            }
            item = LItem.FindControl("rblModel");
            if (item == null)
            {
                item = LItem.FindControl("rblModelsel");
            }
            if (((item != null) && item.Visible) && Versioned.IsNumeric(((RadioButtonList) item).SelectedValue))
            {
                modelID = Conversions.ToInteger(((RadioButtonList) item).SelectedValue);
            }
            item = LItem.FindControl("ddlQty");
            if (((item != null) && item.Visible) && Versioned.IsNumeric(((DropDownList) item).SelectedValue))
            {
                num = Conversions.ToInteger(((DropDownList) item).SelectedValue);
            }
            item = LItem.FindControl("txtQty");
            if (((item != null) && item.Visible) && Versioned.IsNumeric(((TextBox) item).Text))
            {
                num = Conversions.ToInteger(((TextBox) item).Text);
            }
            try
            {
                enumerator2 = LItem.Controls.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    item = (Control) enumerator2.Current;
                    if ((item is DropDownList) && (item.ID.StartsWith("option") & item.Visible))
                    {
                        collection2.Add(item, null, null, null);
                    }
                    if ((item is RadioButtonList) && (item.ID.StartsWith("option") & item.Visible))
                    {
                        collection4.Add(item, null, null, null);
                    }
                    if ((item is TextBox) && (item.ID.StartsWith("option") & item.Visible))
                    {
                        collection5.Add(item, null, null, null);
                    }
                    if (((item is CheckBox) && ((CheckBox) item).Checked) && (item.ID.StartsWith("chkoption") & item.Visible))
                    {
                        collection.Add(item, null, null, null);
                    }
                    if (((item is FileUpload) && (((FileUpload) item).FileName != "")) && item.Visible)
                    {
                        collection3.Add(item, null, null, null);
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            string optCode = "";
            try
            {
                enumerator3 = collection2.GetEnumerator();
                while (enumerator3.MoveNext())
                {
                    DropDownList list = (DropDownList) enumerator3.Current;
                    optCode = optCode + list.SelectedValue + "-";
                }
            }
            finally
            {
                if (enumerator3 is IDisposable)
                {
                    (enumerator3 as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator4 = collection4.GetEnumerator();
                while (enumerator4.MoveNext())
                {
                    RadioButtonList list2 = (RadioButtonList) enumerator4.Current;
                    optCode = optCode + list2.SelectedValue + "-";
                }
            }
            finally
            {
                if (enumerator4 is IDisposable)
                {
                    (enumerator4 as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator5 = collection.GetEnumerator();
                while (enumerator5.MoveNext())
                {
                    CheckBox box = (CheckBox) enumerator5.Current;
                    optCode = optCode + box.Attributes["OptionValueID"] + "-";
                }
            }
            finally
            {
                if (enumerator5 is IDisposable)
                {
                    (enumerator5 as IDisposable).Dispose();
                }
            }
            string textOptions = "";
            string str6 = "";
            string textOptionsXML = "";
            string str3 = SharedFunctions.GetStoreSettingText(PortalID, "optionseperator.text", SharedFunctions.GetCurrentCulture(), false, true);
            bool flag = SharedFunctions.GetStoreSettingBoolean(PortalID, "showOptionNames.flag", SharedFunctions.GetCurrentCulture());
            if (str3 == "")
            {
                str3 = ",";
            }
            try
            {
                enumerator6 = collection5.GetEnumerator();
                while (enumerator6.MoveNext())
                {
                    TextBox box2 = (TextBox) enumerator6.Current;
                    if (flag)
                    {
                        str6 = box2.Attributes["OptionDesc"] + " : ";
                    }
                    else
                    {
                        str6 = "";
                    }
                    textOptionsXML = textOptionsXML + "<" + box2.ID.ToLower() + ">" + str6 + box2.Text + "</" + box2.ID.ToLower() + ">";
                    if (box2.ToolTip == "")
                    {
                        textOptions = textOptions + str6 + box2.Text + str3;
                    }
                    else
                    {
                        textOptions = textOptions + str6 + box2.ToolTip + "=" + box2.Text + str3;
                    }
                }
            }
            finally
            {
                if (enumerator6 is IDisposable)
                {
                    (enumerator6 as IDisposable).Dispose();
                }
            }
            try
            {
                enumerator7 = collection3.GetEnumerator();
                while (enumerator7.MoveNext())
                {
                    FileUpload fu = (FileUpload) enumerator7.Current;
                    try
                    {
                        textOptionsXML = textOptionsXML + "<" + fu.ID.ToLower() + ">" + UploadOrderFile(fu) + "</" + fu.ID.ToLower() + ">";
                        continue;
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        textOptionsXML = textOptionsXML + "<" + fu.ID.ToLower() + ">ERROR</" + fu.ID.ToLower() + ">";
                        ProjectData.ClearProjectError();
                        continue;
                    }
                }
            }
            finally
            {
                if (enumerator7 is IDisposable)
                {
                    (enumerator7 as IDisposable).Dispose();
                }
            }
            if (textOptions.EndsWith(str3))
            {
                textOptions = textOptions.Substring(0, textOptions.Length - str3.Length);
            }
            if (textOptionsXML != "")
            {
                textOptionsXML = "<root>" + textOptionsXML + "</root>";
            }
            optCode = (modelID.ToString() + "-" + optCode).TrimEnd(new char[] { '-' });
            OptCodeInfo info3 = SharedFunctions.GetOptCodeInfo(PortalID, optCode, UserInfo, textOptions, textOptionsXML);
            optCode = info3.OptCode;
            string cartID = getCartID(PortalID);
            NB_Store_CartItemsInfo cartItemByOptCode = controller.GetCartItemByOptCode(cartID, optCode);
            if ((cartItemByOptCode == null) | (textOptions != ""))
            {
                cartItemByOptCode = new NB_Store_CartItemsInfo {
                    OptCode = optCode,
                    ItemDesc = info3.ItemDesc,
                    DateCreated = DateAndTime.Now,
                    Discount = info3.Discount,
                    ItemID = -1,
                    ModelID = modelID,
                    Quantity = num,
                    Tax = decimal.Zero,
                    UnitCost = info3.UnitCost,
                    XMLInfo = textOptionsXML
                };
            }
            else
            {
                cartItemByOptCode.DateCreated = DateAndTime.Now;
                cartItemByOptCode.Discount = info3.Discount;
                if (IncrementCart)
                {
                    cartItemByOptCode.Quantity += num;
                }
                else
                {
                    cartItemByOptCode.Quantity = num;
                }
                cartItemByOptCode.Tax = decimal.Zero;
                cartItemByOptCode.ItemDesc = info3.ItemDesc;
                cartItemByOptCode.UnitCost = info3.UnitCost;
            }
            if (modelID >= 0)
            {
                AddItemToCart(PortalID, cartItemByOptCode, Request);
            }
            ValidateCart(PortalID, UserInfo);
        }

        public static ArrayList AdjustCartStockInModels(int PortalID, ArrayList aryList)
        {
            IEnumerator enumerator=null;
            ArrayList list2 = new ArrayList();
            bool flag = false;
            SettingsController controller2 = new SettingsController();
            CartController controller = new CartController();
            NB_Store_SettingsInfo info2 = controller2.GetSetting(PortalID, "lockstockoncart", SharedFunctions.GetCurrentCulture());
            if (info2 != null)
            {
                flag = Conversions.ToBoolean(info2.SettingValue);
            }
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                    if (current.QtyRemaining >= 0)
                    {
                        int num=0;
                        if (flag)
                        {
                            num = controller.GetCartModelQty(PortalID, current.ModelID, "");
                        }
                        else
                        {
                            num = controller.GetCartModelQty(PortalID, current.ModelID, getCartID(PortalID));
                        }
                        current.QtyRemaining -= num;
                        if (current.QtyRemaining > 0)
                        {
                            list2.Add(current);
                        }
                    }
                    else
                    {
                        list2.Add(current);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return list2;
        }

        private static void AllocateAcrossCart(int PortalID, ArrayList detInfoList, decimal CartDiscount, decimal TotalInCart, bool AllowMultiDis)
        {
            if (decimal.Compare(TotalInCart, decimal.Zero) > 0)
            {
                NB_Store_CartItemsInfo current;
                IEnumerator enumerator=null;
                IEnumerator enumerator2=null;
                decimal num4 = CartDiscount;
                CartController controller = new CartController();
                ArrayList list = (ArrayList) detInfoList.Clone();
                decimal num2 = decimal.Divide(CartDiscount, TotalInCart);
                try
                {
                    enumerator = detInfoList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        current = (NB_Store_CartItemsInfo) enumerator.Current;
                        decimal num = decimal.Multiply(num2, decimal.Add(current.UnitCost, current.Discount));
                        if (!AllowMultiDis)
                        {
                            if (decimal.Compare(decimal.Multiply(num, decimal.MinusOne), current.Discount) < 0)
                            {
                                CartDiscount = decimal.Add(CartDiscount, decimal.Multiply(decimal.Multiply(current.Discount, decimal.MinusOne), new decimal(current.Quantity)));
                                current.Discount = decimal.Multiply(num, decimal.MinusOne);
                                CartDiscount = decimal.Subtract(CartDiscount, decimal.Multiply(num, new decimal(current.Quantity)));
                            }
                        }
                        else
                        {
                            num4 = decimal.Subtract(num4, SharedFunctions.RoundToStoreCurrency(PortalID, Convert.ToDouble(decimal.Multiply(current.Discount, new decimal(current.Quantity)))));
                            if (decimal.Compare(CartDiscount, num) < 0)
                            {
                                current.Discount = decimal.Subtract(current.Discount, CartDiscount);
                                CartDiscount = new decimal();
                            }
                            else
                            {
                                current.Discount = decimal.Subtract(current.Discount, num);
                                CartDiscount = decimal.Subtract(CartDiscount, decimal.Multiply(num, new decimal(current.Quantity)));
                            }
                        }
                        controller.UpdateObjCartItem(current);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                if (((decimal.Compare(CartDiscount, decimal.Zero) > 0) & AllowMultiDis) && (detInfoList.Count > 0))
                {
                    current = (NB_Store_CartItemsInfo) detInfoList[0];
                    current.Discount = decimal.Subtract(current.Discount, CartDiscount);
                    controller.UpdateObjCartItem(current);
                }
                decimal num3 = new decimal();
                int num5 = 0;
                try
                {
                    enumerator2 = list.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        current = (NB_Store_CartItemsInfo) enumerator2.Current;
                        num5++;
                        num3 = decimal.Add(num3, SharedFunctions.RoundToStoreCurrency(PortalID, Convert.ToDouble(decimal.Multiply(current.Discount, new decimal(current.Quantity)))));
                        if ((num5 == detInfoList.Count) && (decimal.Compare(decimal.Add(num3, num4), decimal.Zero) != 0))
                        {
                            current.Discount = decimal.Add(current.Discount, decimal.Multiply(decimal.Divide(decimal.Add(num4, num3), new decimal(current.Quantity)), decimal.MinusOne));
                            controller.UpdateObjCartItem(current);
                        }
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
            }
        }

        public static decimal calcCartLevelDiscount(int PortalID, UserInfo UserInfo, bool AllowMultiDis)
        {
            PromoController controller2 = new PromoController();
            CartController controller = new CartController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            currentCart.CartDiscount = controller2.getCartLevelDiscount(PortalID, UserInfo, AllowMultiDis);
            controller.UpdateObjCart(currentCart);
            decimal num2 = decimal.Multiply(currentCart.CartDiscount, decimal.MinusOne);
            if (decimal.Compare(num2, decimal.Zero) > 0)
            {
                ArrayList currentCartItems = GetCurrentCartItems(PortalID);
                decimal cartItemTotal = GetCartItemTotal(PortalID, false);
                AllocateAcrossCart(PortalID, currentCartItems, num2, cartItemTotal, AllowMultiDis);
            }
            return currentCart.CartDiscount;
        }

        public static decimal calcCouponLevelDiscount(int PortalID, UserInfo UserInfo, string CouponCode, bool AllowMultiDis)
        {
            PromoController controller2 = new PromoController();
            CartController controller = new CartController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            decimal num2 = controller2.getCouponLevelDiscount(PortalID, UserInfo, CouponCode);
            if ((decimal.Compare(num2, decimal.Zero) < 0) && !AllowMultiDis)
            {
                controller2.ClearCartItemDiscount(PortalID);
                num2 = controller2.getCouponLevelDiscount(PortalID, UserInfo, CouponCode);
            }
            if (AllowMultiDis)
            {
                NB_Store_CartInfo info3 = currentCart;
                info3.CartDiscount = decimal.Add(info3.CartDiscount, num2);
            }
            else if (decimal.Compare(num2, currentCart.CartDiscount) < 0)
            {
                currentCart.CartDiscount = num2;
            }
            controller.UpdateObjCart(currentCart);
            decimal num3 = new decimal();
            num2 = decimal.Multiply(num2, decimal.MinusOne);
            if (decimal.Compare(num2, decimal.Zero) > 0)
            {
                IEnumerator enumerator=null;
                ArrayList detInfoList = controller2.getCouponCartItems(PortalID, CouponCode);
                try
                {
                    enumerator = detInfoList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_CartItemsInfo current = (NB_Store_CartItemsInfo) enumerator.Current;
                        num3 = decimal.Add(num3, decimal.Add(decimal.Multiply(new decimal(current.Quantity), current.UnitCost), decimal.Multiply(new decimal(current.Quantity), current.Discount)));
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                AllocateAcrossCart(PortalID, detInfoList, num2, num3, AllowMultiDis);
            }
            return currentCart.CartDiscount;
        }

        public static void CancelOrder(int PortalID)
        {
            CartController controller = new CartController();
            OrderController controller2 = new OrderController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            NB_Store_OrdersInfo order = controller2.GetOrder(currentCart.OrderID);
            if (order != null)
            {
                if (order.OrderNumber == "")
                {
                    controller2.DeleteOrder(currentCart.OrderID);
                }
                else
                {
                    order.OrderStatusID = 30;
                    controller2.UpdateObjOrder(order);
                }
            }
            controller.DeleteCart(currentCart.CartID);
        }

        public static string CreateCartFromOrder(string PortalID, int OrderID, bool CreateNewOrder)
        {
            OrderController controller2 = new OrderController();
            CartController controller = new CartController();
            string cartID = getCartID(Conversions.ToInteger(PortalID));
            controller.DeleteCart(cartID);
            NB_Store_OrdersInfo order = controller2.GetOrder(OrderID);
            if (order != null)
            {
                IEnumerator enumerator=null;
                NB_Store_AddressInfo orderAddress = controller2.GetOrderAddress(order.BillingAddressID);
                NB_Store_CartInfo objInfo = new NB_Store_CartInfo {
                    BankHtmlRedirect = "",
                    BankTransID = -1,
                    CartDiscount = order.Discount,
                    CartID = cartID,
                    CountryCode = orderAddress.CountryCode,
                    DateCreated = DateAndTime.Now
                };
                if (CreateNewOrder)
                {
                    objInfo.OrderID = -1;
                }
                else
                {
                    objInfo.OrderID = OrderID;
                }
                objInfo.PortalID = Conversions.ToInteger(PortalID);
                objInfo.PromoCode = "";
                objInfo.ShipMethodID = SharedFunctions.GetDefaultShipMethod(Conversions.ToInteger(PortalID));
                objInfo.ShipType = "";
                objInfo.UserID = -1;
                objInfo.VATNumber = "";
                objInfo.XMLInfo = order.CartXMLInfo;
                controller.UpdateObjCart(objInfo);
                ArrayList orderDetailList = controller2.GetOrderDetailList(OrderID);
                try
                {
                    enumerator = orderDetailList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                        NB_Store_CartItemsInfo objCIInfo = new NB_Store_CartItemsInfo {
                            CartID = cartID,
                            DateCreated = DateAndTime.Now,
                            Discount = current.Discount,
                            ItemDesc = current.ItemDesc,
                            ModelID = current.ModelID,
                            OptCode = current.OptCode,
                            Quantity = current.Quantity,
                            Tax = current.Tax,
                            UnitCost = current.UnitCost,
                            ProductURL = current.ProductURL,
                            XMLInfo = current.CartXMLInfo
                        };
                        AddItemToCart(Conversions.ToInteger(PortalID), objCIInfo, null);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
            return cartID;
        }

        public static NB_Store_OrdersInfo CreateOrder(int UserID, int PortalID, string NoteMsg, string OrderEmail, UserInfo UserInfo)
        {
            DateTime time;
            OrderController controller2 = new OrderController();
            NB_Store_SettingsInfo info4 = new SettingsController().GetSetting(PortalID, "ordershipdate.days", SharedFunctions.GetCurrentCulture());
            if (info4 == null)
            {
                time = new DateTime();
            }
            else if (Versioned.IsNumeric(info4.SettingValue))
            {
                time = DateAndTime.DateAdd(DateInterval.Day, (double) Conversions.ToInteger(info4.SettingValue), DateAndTime.Today);
            }
            else
            {
                time = new DateTime();
            }
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            ValidateCart(PortalID, UserInfo);
            NB_Store_OrdersInfo order = controller2.GetOrder(currentCart.OrderID);
            int orderID = -1;
            if (order != null)
            {
                if (!order.OrderIsPlaced)
                {
                    controller2.DeleteOrder(order.OrderID);
                    order = new NB_Store_OrdersInfo();
                }
                else
                {
                    orderID = order.OrderID;
                    if (order.OrderGUID == "")
                    {
                        orderID = -1;
                        order = new NB_Store_OrdersInfo();
                    }
                    else if (order.OrderStatusID == 40)
                    {
                        orderID = -1;
                        order = new NB_Store_OrdersInfo();
                    }
                }
            }
            else
            {
                order = new NB_Store_OrdersInfo();
            }
            order.BillingAddressID = -1;
            order.NoteMsg = NoteMsg;
            order.OrderDate = DateAndTime.Now;
            order.OrderID = orderID;
            order.OrderStatusID = 10;
            order.PayType = "";
            order.PortalID = PortalID;
            order.PromoCode = currentCart.PromoCode;
            order.ShipDate = time;
            order.ShippingAddressID = -1;
            order.UserID = UserID;
            order.VATNumber = currentCart.VATNumber;
            order.Email = OrderEmail;
            order.ShipMethodID = currentCart.ShipMethodID;
            order.TrackingCode = "";
            order.ElapsedDate = Null.NullDate;
            order.CartXMLInfo = currentCart.XMLInfo;
            order.Referrer = currentCart.Referrer;
            order = CreateOrderTotals(order, currentCart);
            order = controller2.UpdateObjOrder(order);
            SharedFunctions.updateOrderActionLog(order, UserInfo, 10);
            CreateOrderDetails(PortalID, order.OrderID);
            CartController controller = new CartController();
            currentCart.OrderID = order.OrderID;
            controller.UpdateObjCart(currentCart);
            if (EventInterface.Instance() != null)
            {
                EventInterface.Instance().CreateOrder(PortalID, order.OrderID);
            }
            return order;
        }

        public static void CreateOrderDetails(int PortalID, int OrderID)
        {
            IEnumerator enumerator=null;
            IEnumerator enumerator2=null;
            OrderController controller = new OrderController();
            ProductController controller2 = new ProductController();
            ArrayList orderDetailList = controller.GetOrderDetailList(OrderID);
            try
            {
                enumerator = orderDetailList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                    controller.DeleteOrderDetail(current.OrderDetailID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            orderDetailList = GetCurrentCartItems(PortalID);
            try
            {
                enumerator2 = orderDetailList.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    NB_Store_CartItemsInfo info4 = (NB_Store_CartItemsInfo) enumerator2.Current;
                    NB_Store_OrderDetailsInfo objInfo = new NB_Store_OrderDetailsInfo {
                        Discount = info4.Discount,
                        ItemDesc = info4.ItemDesc,
                        ModelID = info4.ModelID,
                        OptCode = info4.OptCode,
                        OrderDetailID = -1,
                        OrderID = OrderID,
                        Quantity = info4.Quantity,
                        Tax = info4.Tax,
                        UnitCost = info4.UnitCost,
                        ProductURL = info4.ProductURL,
                        CartXMLInfo = info4.XMLInfo
                    };
                    NB_Store_ModelInfo model = controller2.GetModel(info4.ModelID, SharedFunctions.GetCurrentCulture());
                    if (model == null)
                    {
                        objInfo.PurchaseCost = decimal.Zero;
                    }
                    else
                    {
                        objInfo.PurchaseCost = model.PurchaseCost;
                    }
                    controller.UpdateObjOrderDetail(objInfo);
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
        }

        public static NB_Store_OrdersInfo CreateOrderTotals(NB_Store_OrdersInfo objInfo, NB_Store_CartInfo objCInfo)
        {
            CartTotals totals = GetCalulatedTotals(objInfo.PortalID, objCInfo.VATNumber, objCInfo.CountryCode, objCInfo.ShipType, objCInfo.ShipMethodID);
            objInfo.AppliedTax = totals.TaxAppliedAmt;
            objInfo.CalculatedTax = totals.TaxAmt;
            objInfo.Discount = totals.DiscountAmt;
            objInfo.ShippingCost = totals.ShipAmt;
            objInfo.Total = totals.OrderTotal;
            return objInfo;
        }

        public static int CheckStock(int ModelID, int Qty)
        {
            ProductController controller = new ProductController();
            int allow = Qty;
            NB_Store_ModelInfo model = controller.GetModel(ModelID, SharedFunctions.GetCurrentCulture());
            int qtyRemaining = model.QtyRemaining;
            if (SharedFunctions.GetStoreSettingBoolean(model.PortalID, "lockstockoncart") & (qtyRemaining > 0))
            {
                CartController controller2 = new CartController();
                int num4 = 0;
                num4 = controller2.GetCartModelQty(model.PortalID, model.ModelID, "");
                qtyRemaining -= num4 - Qty;
                if (qtyRemaining < 0)
                {
                    qtyRemaining = 0;
                }
            }
            if ((qtyRemaining >= 0) && (qtyRemaining < Qty))
            {
                if ((DateTime.Compare(DateAndTime.Now, DateAndTime.DateAdd(DateInterval.Minute, 10.0, model.QtyTransDate)) < 0) && (model.QtyTrans > 0))
                {
                    qtyRemaining -= model.QtyTrans;
                }
                allow = qtyRemaining;
            }
            if (((model.Allow >= 0) & SharedFunctions.GetStoreSettingBoolean(model.PortalID, "allowcartmodellimit.flag")) && (allow > model.Allow))
            {
                allow = model.Allow;
            }
            return allow;
        }

        public static int CheckStockByCartItemID(int PortalID, int CartItemID, int Qty)
        {
            int num2 = Qty;
            NB_Store_CartItemsInfo currentCartItem = GetCurrentCartItem(PortalID, CartItemID);
            if (currentCartItem != null)
            {
                num2 = CheckStock(currentCartItem.ModelID, Qty);
            }
            return num2;
        }

        public static void DeleteCart(int PortalID)
        {
            CartController controller = new CartController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            controller.DeleteCart(currentCart.CartID);
        }

        public static void DeleteCartItems(int PortalID)
        {
            IEnumerator enumerator=null;
            CartController controller = new CartController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            ArrayList cartItemList = controller.GetCartItemList(currentCart.CartID);
            try
            {
                enumerator = cartItemList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CartItemsInfo current = (NB_Store_CartItemsInfo) enumerator.Current;
                    controller.DeleteCartItem(current.ItemID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public static CartTotals GetCalulatedTotals(int PortalID, int ShipMethodID = -1)
        {
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            return GetCalulatedTotals(PortalID, currentCart.VATNumber, currentCart.CountryCode, currentCart.ShipType, ShipMethodID, currentCart);
        }

        public static CartTotals GetCalulatedTotals(int PortalID, string VATCode, string CountryCode, string ShipType, int ShipMethodID)
        {
            return GetCalulatedTotals(PortalID, VATCode, CountryCode, ShipType, ShipMethodID, null);
        }

        public static CartTotals GetCalulatedTotals(int PortalID, string VATCode, string CountryCode, string ShipType, int ShipMethodID, NB_Store_CartInfo objCart)
        {
            CartTotals objCartTotals = null;
            ShipController controller = new ShipController();
            TaxCalcController controller2 = new TaxCalcController(PortalID);
            if (CalcCartInterface.Instance() != null)
            {
                objCartTotals = CalcCartInterface.Instance().getCartTotals(PortalID, getCartID(PortalID));
            }
            if (objCartTotals == null)
            {
                IEnumerator enumerator=null;
                objCartTotals = new CartTotals();
                ArrayList currentCartItems = GetCurrentCartItems(PortalID);
                try
                {
                    enumerator = currentCartItems.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_CartItemsInfo current = (NB_Store_CartItemsInfo) enumerator.Current;
                        CartTotals totals3 = objCartTotals;
                        totals3.DiscountAmt = decimal.Add(totals3.DiscountAmt, SharedFunctions.RoundToStoreCurrency(Convert.ToDouble(decimal.Multiply(new decimal(current.Quantity), current.Discount))));
                        totals3 = objCartTotals;
                        totals3.TaxAmt = decimal.Add(totals3.TaxAmt, current.Tax);
                        totals3 = objCartTotals;
                        totals3.TotalAmt = decimal.Add(totals3.TotalAmt, SharedFunctions.RoundToStoreCurrency(Convert.ToDouble(decimal.Multiply(new decimal(current.Quantity), current.UnitCost))));
                        totals3 = objCartTotals;
                        totals3.Qty += current.Quantity;
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
            if (CalcShipInterface.Instance() != null)
            {
                objCartTotals = CalcShipInterface.Instance().getCartTotals(PortalID, getCartID(PortalID), objCartTotals, ShipType, CountryCode, ShipMethodID);
            }
            else if (ShipType == "NONE")
            {
                objCartTotals.ShipAmt = decimal.Zero;
            }
            else
            {
                if (ShipMethodID < 0)
                {
                    ShipMethodID = SharedFunctions.GetDefaultShipMethod(PortalID);
                }
                objCartTotals.ShipAmt = controller.getShippingCost(PortalID, CountryCode, ShipMethodID);
            }
            if (CalcTaxInterface.Instance() != null)
            {
                objCartTotals = CalcTaxInterface.Instance().getCartTotals(PortalID, getCartID(PortalID), objCartTotals, CountryCode, VATCode);
            }
            else
            {
                CartTaxInfo info = controller2.getCartTaxDetails(PortalID, objCartTotals.ShipAmt, SharedFunctions.GetMerchantCountryCode(PortalID), VATCode);
                if (info.TaxOption == "3")
                {
                    objCartTotals.TaxAppliedAmt = decimal.Add(Conversions.ToDecimal(info.TaxAmount), Conversions.ToDecimal(info.ShipTax));
                }
                else if (info.TaxOption == "2")
                {
                    if (decimal.Compare(Conversions.ToDecimal(info.TaxAmount), decimal.Zero) < 0)
                    {
                        objCartTotals.TaxAppliedAmt = Conversions.ToDecimal(info.TaxAmount);
                    }
                    else
                    {
                        objCartTotals.TaxAppliedAmt = decimal.Zero;
                    }
                }
                else
                {
                    objCartTotals.TaxAppliedAmt = decimal.Zero;
                }
                objCartTotals.TaxAmt = decimal.Add(Conversions.ToDecimal(info.TaxAmount), Conversions.ToDecimal(info.ShipTax));
            }
            if (CalcDiscountInterface.Instance() != null)
            {
                objCartTotals = CalcDiscountInterface.Instance().getCartTotals(PortalID, getCartID(PortalID), objCartTotals);
            }
            else if (decimal.Compare(decimal.Add(objCartTotals.TotalAmt, objCartTotals.DiscountAmt), decimal.Zero) < 0)
            {
                objCartTotals.DiscountAmt = decimal.Multiply(objCartTotals.TotalAmt, decimal.MinusOne);
            }
            if (decimal.Compare(objCartTotals.ShipAmt, decimal.Zero) < 0)
            {
                objCartTotals.OrderTotal = decimal.Add(decimal.Add(objCartTotals.TotalAmt, objCartTotals.TaxAppliedAmt), objCartTotals.DiscountAmt);
            }
            else
            {
                objCartTotals.OrderTotal = decimal.Add(decimal.Add(decimal.Add(objCartTotals.TotalAmt, objCartTotals.TaxAppliedAmt), objCartTotals.ShipAmt), objCartTotals.DiscountAmt);
            }
            if (decimal.Compare(objCartTotals.OrderTotal, decimal.Zero) < 0)
            {
                objCartTotals.OrderTotal = decimal.Zero;
            }
            if ((objCart != null) && (objCart.OrderID > 0))
            {
                NB_Store_OrdersInfo order = new OrderController().GetOrder(objCart.OrderID);
                if ((order != null) && (decimal.Compare(order.AlreadyPaid, decimal.Zero) > 0))
                {
                    objCartTotals.Balance = decimal.Subtract(objCartTotals.OrderTotal, order.AlreadyPaid);
                }
            }
            return objCartTotals;
        }

        public static string getCartID(int PortalID)
        {
            string str = "NB_Store_Portal_";
            if (SharedFunctions.GetStoreSetting(PortalID, "cookiecart.byuser", "None") == "1")
            {
                str = str + "_" + HttpContext.Current.User.Identity.Name + "_";
            }
            string cartID = "";
            HttpCookie cookie = HttpContext.Current.Request.Cookies[str + PortalID.ToString()];
            if (cookie != null)
            {
                return cookie["CartID"];
            }
            cartID = Guid.NewGuid().ToString();
            setCartID(PortalID, cartID);
            return cartID;
        }

        public static decimal GetCartItemTotal(int PortalID, bool lessDiscount = false)
        {
            IEnumerator enumerator=null;
            decimal num2 = new decimal();
            ArrayList currentCartItems = GetCurrentCartItems(PortalID);
            try
            {
                enumerator = currentCartItems.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CartItemsInfo current = (NB_Store_CartItemsInfo) enumerator.Current;
                    num2 = decimal.Add(num2, decimal.Multiply(new decimal(current.Quantity), current.UnitCost));
                    if (lessDiscount)
                    {
                        num2 = decimal.Add(num2, decimal.Add(new decimal(current.Quantity), current.Discount));
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (decimal.Compare(num2, decimal.Zero) < 0)
            {
                num2 = new decimal();
            }
            return num2;
        }

        public static NB_Store_CartInfo GetCurrentCart(int PortalID)
        {
            return GetCurrentCart(PortalID, null);
        }

        public static NB_Store_CartInfo GetCurrentCart(int PortalID, HttpRequest Request)
        {
            CartController controller = new CartController();
            string cartID = getCartID(PortalID);
            NB_Store_CartInfo cart = controller.GetCart(cartID);
            if (cart == null)
            {
                cart = new NB_Store_CartInfo {
                    CartID = cartID,
                    DateCreated = DateAndTime.Now,
                    OrderID = -1,
                    PortalID = PortalID,
                    UserID = -1,
                    ShipMethodID = SharedFunctions.GetDefaultShipMethod(PortalID),
                    Referrer = ""
                };
                if ((Request != null) && (Request.UrlReferrer != null))
                {
                    cart.Referrer = Request.UrlReferrer.AbsoluteUri;
                }
                controller.UpdateObjCart(cart);
                return cart;
            }
            if (((cart.Referrer == "") && (Request != null)) && (Request.UrlReferrer != null))
            {
                cart.Referrer = Request.UrlReferrer.AbsoluteUri;
                controller.UpdateObjCart(cart);
            }
            return cart;
        }

        public static NB_Store_CartItemsInfo GetCurrentCartItem(int PortalID, int CartItemID)
        {
            CartController controller = new CartController();
            string str = getCartID(PortalID);
            return controller.GetCartItem(CartItemID);
        }

        public static ArrayList GetCurrentCartItems(int PortalID)
        {
            CartController controller = new CartController();
            string cartID = getCartID(PortalID);
            return controller.GetCartItemList(cartID);
        }

        public static NB_Store_CartItemsInfo GetLastCartItem(int PortalID)
        {
            ArrayList currentCartItems = GetCurrentCartItems(PortalID);
            if (currentCartItems.Count >= 1)
            {
                return (NB_Store_CartItemsInfo) currentCartItems[currentCartItems.Count - 1];
            }
            return null;
        }

        public static bool IsCartAboveMinimum(int PortalID)
        {
            SettingsController controller = new SettingsController();
            double num = -1.0;
            NB_Store_SettingsInfo info = controller.GetSetting(PortalID, "minimumcarttotal.limit", SharedFunctions.GetCurrentCulture());
            if ((info != null) && Versioned.IsNumeric(info.SettingValue))
            {
                num = Conversions.ToDouble(info.SettingValue);
            }
            if ((num > 0.0) && (Convert.ToDouble(GetCartItemTotal(PortalID, false)) < num))
            {
                return false;
            }
            return true;
        }

        public static bool IsCartEmpty(int PortalID)
        {
            CartController controller = new CartController();
            string cartID = getCartID(PortalID);
            return (controller.GetCartItemList(cartID).Count == 0);
        }

        public static void RemoveItemFromCart(int ItemId)
        {
            new CartController().DeleteCartItem(ItemId);
        }

        public static void Save(NB_Store_CartInfo objCInfo)
        {
            new CartController().UpdateObjCart(objCInfo);
        }

        public static void SaveShipType(int PortalID, string ShipType)
        {
            CartController controller = new CartController();
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            currentCart.ShipType = ShipType;
            controller.UpdateObjCart(currentCart);
        }

        private static void setCartID(int PortalID, string cartID)
        {
            string str = "NB_Store_Portal_";
            if (SharedFunctions.GetStoreSetting(PortalID, "cookiecart.byuser", "None") == "1")
            {
                str = str + "_" + HttpContext.Current.User.Identity.Name + "_";
            }
            HttpCookie cookie = new HttpCookie(str + PortalID.ToString());
            cookie["CartID"] = cartID;
            int num = 30;
            if (SharedFunctions.GetStoreSetting(PortalID, "cookiecart.expire", "None") == "0")
            {
                cookie.Expires = DateTime.MinValue;
            }
            else
            {
                if (Versioned.IsNumeric(SharedFunctions.GetStoreSetting(PortalID, "cookiecart.expire", "None")))
                {
                    num = Conversions.ToInteger(SharedFunctions.GetStoreSetting(PortalID, "cookiecart.expire", "None"));
                }
                cookie.Expires = DateAndTime.DateAdd(DateInterval.Day, (double) num, DateAndTime.Today);
            }
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public static void UpdateCartItemQty(int ItemId, int NewQty)
        {
            CartController controller = new CartController();
            NB_Store_CartItemsInfo cartItem = controller.GetCartItem(ItemId);
            if (cartItem != null)
            {
                cartItem.Quantity = NewQty;
                cartItem.DateCreated = DateAndTime.Now;
                controller.UpdateObjCartItem(cartItem);
            }
        }

        public static void UpdateCartItemUnitCost(int ItemId, decimal UnitCost)
        {
            CartController controller = new CartController();
            NB_Store_CartItemsInfo cartItem = controller.GetCartItem(ItemId);
            if (cartItem != null)
            {
                cartItem.UnitCost = UnitCost;
                cartItem.DateCreated = DateAndTime.Now;
                controller.UpdateObjCartItem(cartItem);
            }
        }

        private static string UploadOrderFile(FileUpload fu)
        {
            FileSystemUtils utils = new FileSystemUtils();
            ProductController controller = new ProductController();
            string strFileNamePath = "";
            if (fu.FileName != "")
            {
                PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
                SharedFunctions.CreateDir(currentPortalSettings, "orderuploads");
                string str2 = Guid.NewGuid().ToString();
                strFileNamePath = currentPortalSettings.HomeDirectoryMapPath + @"orderuploads\" + str2 + Path.GetExtension(fu.FileName);
                string subFolderPath = DotNetNuke.Common.Globals.GetSubFolderPath(strFileNamePath, currentPortalSettings.PortalId);
                FileSystemUtils.UploadFile(strFileNamePath, fu.PostedFile);
                FileSystemUtils.MoveFile(strFileNamePath + fu.FileName, strFileNamePath, currentPortalSettings);
                if (FileSystemUtils.GetFolder(currentPortalSettings.PortalId, "orderuploads").StorageLocation == 1)
                {
                    strFileNamePath = currentPortalSettings.HomeDirectoryMapPath + @"orderuploads\" + str2 + Path.GetExtension(fu.FileName) + ".resources";
                }
            }
            return strFileNamePath;
        }

        public static void ValidateCart(int PortalID, UserInfo UserInfo)
        {
            IEnumerator enumerator=null;
            ProductController controller2 = new ProductController();
            CartController controller = new CartController();
            TaxCalcController controller4 = new TaxCalcController(PortalID);
            SettingsController controller3 = new SettingsController();
            ArrayList currentCartItems = GetCurrentCartItems(PortalID);
            try
            {
                enumerator = currentCartItems.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CartItemsInfo current = (NB_Store_CartItemsInfo) enumerator.Current;
                    NB_Store_ModelInfo model = controller2.GetModel(current.ModelID, SharedFunctions.GetCurrentCulture());
                    NB_Store_ProductsInfo product = controller2.GetProduct(model.ProductID, SharedFunctions.GetCurrentCulture());
                    if ((product == null) | (model == null))
                    {
                        RemoveItemFromCart(current.ItemID);
                    }
                    else
                    {
                        if ((product.Archived | product.IsDeleted) | model.Deleted)
                        {
                            RemoveItemFromCart(current.ItemID);
                            continue;
                        }
                        bool flag2 = true;
                        string storeSetting = SharedFunctions.GetStoreSetting(PortalID, "categorypurchase.list");
                        if (storeSetting != "")
                        {
                            string[] strArray = Strings.Split(storeSetting, ",", -1, CompareMethod.Binary);
                            flag2 = false;
                            int upperBound = strArray.GetUpperBound(0);
                            for (int i = 0; i <= upperBound; i++)
                            {
                                IEnumerator enumerator2=null;
                                ArrayList categoriesAssigned = controller2.GetCategoriesAssigned(product.ProductID);
                                try
                                {
                                    enumerator2 = categoriesAssigned.GetEnumerator();
                                    while (enumerator2.MoveNext())
                                    {
                                        NB_Store_ProductCategoryInfo info7 = (NB_Store_ProductCategoryInfo) enumerator2.Current;
                                        if (Versioned.IsNumeric(strArray[i]) && (info7.CategoryID == Conversions.ToInteger(strArray[i])))
                                        {
                                            flag2 = true;
                                            continue;
                                        }
                                    }
                                }
                                finally
                                {
                                    if (enumerator2 is IDisposable)
                                    {
                                        (enumerator2 as IDisposable).Dispose();
                                    }
                                }
                            }
                            if (!flag2)
                            {
                                RemoveItemFromCart(current.ItemID);
                            }
                        }
                        if (flag2)
                        {
                            int num2 = CheckStock(current.ModelID, current.Quantity);
                            if (num2 > 0)
                            {
                                int num3 = 0xf423f;
                                NB_Store_SettingsInfo info6 = controller3.GetSetting(PortalID, "productqty.limit", SharedFunctions.GetCurrentCulture());
                                if ((info6 != null) && Versioned.IsNumeric(info6.SettingValue))
                                {
                                    num3 = Conversions.ToInteger(info6.SettingValue);
                                    if (num2 > num3)
                                    {
                                        num2 = num3;
                                    }
                                }
                                current.Quantity = num2;
                                OptCodeInfo info8 = SharedFunctions.GetOptCodeInfo(PortalID, current.OptCode, UserInfo, "", current.XMLInfo);
                                if (info8.OptCode == "")
                                {
                                    RemoveItemFromCart(current.ItemID);
                                }
                                else
                                {
                                    if (!current.StaticAmts)
                                    {
                                        NB_Store_CartInfo info9 = GetCurrentCart(PortalID);
                                        if (info9.OrderID > 0)
                                        {
                                            NB_Store_OrdersInfo order = new OrderController().GetOrder(info9.OrderID);
                                            if (order != null)
                                            {
                                                if (order.OrderGUID == "")
                                                {
                                                    current.Discount = info8.Discount;
                                                    current.UnitCost = info8.UnitCost;
                                                }
                                            }
                                            else
                                            {
                                                current.Discount = info8.Discount;
                                                current.UnitCost = info8.UnitCost;
                                            }
                                        }
                                        else
                                        {
                                            current.Discount = info8.Discount;
                                            current.UnitCost = info8.UnitCost;
                                        }
                                    }
                                    ProductTaxInfo info5 = controller4.getProductTaxDetails(PortalID, current);
                                    current.Tax = Conversions.ToDecimal(info5.TaxAmount);
                                    controller.UpdateObjCartItem(current);
                                }
                                continue;
                            }
                            RemoveItemFromCart(current.ItemID);
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            NB_Store_CartInfo currentCart = GetCurrentCart(PortalID);
            string str = SharedFunctions.GetStoreSetting(PortalID, "allowmultidiscount.flag", "None");
            if (str == "")
            {
                str = "false";
            }
            bool allowMultiDis = Conversions.ToBoolean(str);
            calcCartLevelDiscount(PortalID, UserInfo, allowMultiDis);
            calcCouponLevelDiscount(PortalID, UserInfo, currentCart.PromoCode, allowMultiDis);
        }
    }
}

